import 'package:dark_notes/models/notemodel.dart';
import 'package:dark_notes/pages/newnotepage.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class ViewNotePage extends StatelessWidget {
  final String title;
  final Note note;
  ViewNotePage({this.title, this.note});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        title: Text(this.title),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.delete, color: Colors.red),
            onPressed: () {
              Provider.of<NoteModel>(context, listen: false).remove(note);
              Navigator.pop(context);
            },
          ),
        ],
      ),
      body: Container(
        padding: EdgeInsets.all(15),
        child: Consumer<NoteModel>(builder: (context, noteModel, child) {
          return ListView(
            children: <Widget>[
              Row(children: <Widget>[
                Expanded(
                    child: Text(
                  this.note.title,
                  style: Theme.of(context).textTheme.headline5,
                )),
              ]),
              SizedBox(
                height: 15,
              ),
              Row(
                children: <Widget>[
                  Expanded(
                      child: Text(
                    this.note.body,
                    style: Theme.of(context).textTheme.bodyText1,
                  ))
                ],
              ),
              SizedBox(
                height: 15,
              ),
              // Row(
              //   mainAxisAlignment: MainAxisAlignment.end,
              //   children: <Widget>[
              //     RaisedButton(
              //       child: Text('Edit'),
              //       onPressed: () {
              //         Navigator.push(
              //             context,
              //             MaterialPageRoute(
              //                 builder: (context) => NewNotePage(
              //                     title: 'Edit Note',
              //                     action: 'edit',
              //                     note: note)));
              //       },
              //     )
              //   ],
              // )
            ],
          );
        }),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.edit),
        onPressed: () {
          Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) => NewNotePage(
                      title: 'Edit Note', action: 'edit', note: note)));
        },
      ),
    );
  }
}
